//备注：拷贝代码请加上作者信息
//作者：王海涛
//邮箱：1126471088@qq.com
//版本：V0.1.0
#include "RGB_Convert.h"


typedef union
{
	unsigned int RGB;
	struct
	{
		unsigned int   :3;
		unsigned int B :5;
		unsigned int   :2;
		unsigned int G :6;
		unsigned int   :3;
		unsigned int R :5;
		unsigned int   :8;
	}Word;
}WHT_RGB888_LE_t;//小端模式

typedef union
{
	unsigned int RGB;
	struct
	{
		unsigned int   :3;
		unsigned int R :5;
		unsigned int   :2;
		unsigned int G :6;
		unsigned int   :3;
		unsigned int B :5;
		unsigned int   :8;
	}Word;
}WHT_RGB888_BE_t;//大端模式

typedef union
{
	unsigned short RGB;
	struct
	{
		unsigned short B :5;
		unsigned short G :6;
		unsigned short R :5;
	}Word;
}WHT_RGB565_LE_t;//小端模式

typedef union
{
	unsigned short RGB;
	struct
	{
		unsigned short R :5;
		unsigned short G :6;
		unsigned short B :5;
	}Word;
}WHT_RGB565_BE_t;//大端模式


/*uint32_t RGB888_LE To uint16_t RGB565_LE*/
unsigned short RGB888_LE_To_RGB565_LE(unsigned int RGB888_LE)
{
    WHT_RGB565_LE_t RGB565_LE;

    RGB565_LE.Word.R = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.R;
    RGB565_LE.Word.G = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.G;
    RGB565_LE.Word.B = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.B;
    return RGB565_LE.RGB;
}
/*uint32_t RGB888_LE To uint16_t RGB565_BE*/
unsigned short RGB888_LE_To_RGB565_BE(unsigned int RGB888_LE)
{
    WHT_RGB565_BE_t RGB565_BE;

    RGB565_BE.Word.R = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.R;
    RGB565_BE.Word.G = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.G;
    RGB565_BE.Word.B = ((WHT_RGB888_LE_t*)&RGB888_LE)->Word.B;
    return RGB565_BE.RGB;
}
/*uint32_t RGB888_BE To uint16_t RGB565_LE*/
unsigned short RGB888_BE_To_RGB565_LE(unsigned int RGB888_BE)
{
    WHT_RGB565_LE_t RGB565_LE;

    RGB565_LE.Word.R = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.R;
    RGB565_LE.Word.G = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.G;
    RGB565_LE.Word.B = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.B;
    return RGB565_LE.RGB;
}
/*uint32_t RGB888_BE To uint16_t RGB565_BE*/
unsigned short RGB888_BE_To_RGB565_BE(unsigned int RGB888_BE)
{
    WHT_RGB565_BE_t RGB565_BE;

    RGB565_BE.Word.R = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.R;
    RGB565_BE.Word.G = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.G;
    RGB565_BE.Word.B = ((WHT_RGB888_BE_t*)&RGB888_BE)->Word.B;
    return RGB565_BE.RGB;
}


/*uint16_t RGB565_LE To uint32_t RGB888_LE*/
unsigned int RGB565_LE_To_RGB888_LE(unsigned int RGB565_LE)
{
    WHT_RGB888_LE_t RGB888_LE;

    RGB888_LE.Word.R = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.R;
    RGB888_LE.Word.G = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.G;
    RGB888_LE.Word.B = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.B;
    return RGB888_LE.RGB;
}
/*uint16_t RGB565_LE To uint32_t RGB888_BE*/
unsigned int RGB565_LE_To_RGB888_BE(unsigned int RGB565_LE)
{
    WHT_RGB888_BE_t RGB888_BE;

    RGB888_BE.Word.R = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.R;
    RGB888_BE.Word.G = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.G;
    RGB888_BE.Word.B = ((WHT_RGB565_LE_t*)&RGB565_LE)->Word.B;
    return RGB888_BE.RGB;
}
/*uint16_t RGB565_BE To uint32_t RGB888_LE*/
unsigned int RGB565_BE_To_RGB888_LE(unsigned int RGB565_BE)
{
    WHT_RGB888_LE_t RGB888_LE;

    RGB888_LE.Word.R = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.R;
    RGB888_LE.Word.G = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.G;
    RGB888_LE.Word.B = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.B;
    return RGB888_LE.RGB;
}
/*uint16_t RGB565_BE To uint32_t RGB888_BE*/
unsigned int RGB565_BE_To_RGB888_BE(unsigned int RGB565_BE)
{
    WHT_RGB888_BE_t RGB888_BE;

    RGB888_BE.Word.R = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.R;
    RGB888_BE.Word.G = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.G;
    RGB888_BE.Word.B = ((WHT_RGB565_BE_t*)&RGB565_BE)->Word.B;
    return RGB888_BE.RGB;
}
